﻿namespace CoMiCommon
{
    using System;
    using System.Web;

    public class DataCache
    {
        public static int GetCacheCount()
        {
            return HttpRuntime.Cache.Count;
        }

        public static object GetCache(string CacheKey)
        {
            return HttpRuntime.Cache[CacheKey];
        }

        public static object GetCache(int index)
        {
            
            System.Collections.IDictionaryEnumerator de = HttpRuntime.Cache.GetEnumerator();
            for (int i = 0; de.MoveNext(); ++i)
            {
                if (i == index)
                    return de.Value;
            }
            return null;
        }

        public static object Remove(string key)
        {
            return HttpRuntime.Cache.Remove(key);
        }

        public static void SetCache(string CacheKey, object objObject)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject);
        }

        public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
        }
    }
}

